<?php 
class UserStringHelper{
	/**
	 * return random string
	 * @param number $length length of string
	 * @param string $is_number only nummeric
	 * @param string $has_special include special character
	 */
	public static function random($length = 9, $is_number = false, $has_special = false){
		if($is_number){
			$strPa = '0123456789';
		}else{
			$strPa = 'qwertyuiopasdfghjklzxcvbnm';
			if($has_special){
				$strPa.='~`!@#$%^&*()_-+={[}]|:;"<,>.?/';
			}
		}
		$strReturn = '';
		for($i = 0; $i < $length; $i++){
			$strReturn.=$strPa[rand(0,strlen($strPa)-1)];
		}
		return $strReturn;
	}
	/**
	 * 
	 * @param string $str
	 * @return Ambigous <string, mixed>
	 */
	public static function titleToAddress($str = ''){
		$str = strtolower($str);
		$strReplace = array(
				//Special character
				'&'				=> '-',
				'/'				=> '-',
				'"'				=> '-',
				'('				=> '-',
				')'				=> '-',
				//Normal
				' '				=> '-',
				
				//Boarch
				'ê'					=> 'e',
				'ế'					=> 'e',
				'ề'					=> 'e',
				'ể'					=> 'e',
				'ễ'					=> 'e',
				'ệ'					=> 'e',
				
				'é'					=> 'e',
				'è'					=> 'e',
				'ẻ'					=> 'e',
				'ẽ'					=> 'e',
				'ẹ'					=> 'e',
				
				
				'ú'					=> 'u',
				'ù'					=> 'u',
				'ủ'					=> 'u',
				'ũ'					=> 'u',
				'ụ'					=> 'u',
				
				'ư'					=> 'u',
				'ứ'					=> 'u',
				'ừ'					=> 'u',
				'ử'					=> 'u',
				'ữ'					=> 'u',
				'ự'					=> 'u',
				
				'í'					=> 'i',
				'ì'					=> 'i',
				'ỉ'					=> 'i',
				'ĩ'					=> 'i',
				'ị'					=> 'i',
				
				'ó'					=> 'o',
				'ò'					=> 'o',
				'ỏ'					=> 'o',
				'õ'					=> 'o',
				'ọ'					=> 'o',
				
				'ơ'					=> 'o',
				'ớ'					=> 'o',
				'ờ'					=> 'o',
				'ở'					=> 'o',
				'ỡ'					=> 'o',
				'ợ'					=> 'o',
				
				'ô'					=> 'o',
				'ố'					=> 'o',
				'ồ'					=> 'o',
				'ổ'					=> 'o',
				'ỗ'					=> 'o',
				'ộ'					=> 'o',
				
				
				'á'					=> 'a',
				'à'					=> 'a',
				'ả'					=> 'a',
				'ã'					=> 'a',
				'ạ'					=> 'a',
				
				'â'					=> 'a',
				'ấ'					=> 'a',
				'ầ'					=> 'a',
				'ẩ'					=> 'a',
				'ẫ'					=> 'a',
				'ậ'					=> 'a',
				
				'ă'					=> 'a',
				'ắ'					=> 'a',
				'ằ'					=> 'a',
				'ẳ'					=> 'a',
				'ẵ'					=> 'a',
				'ặ'					=> 'a',
				
				'đ' 				=> 'd',
			);
		foreach($strReplace as $key => $val){
			$str = str_replace($key, $val, $str);
		}
		return $str;
	}
	
}
